package com.shierke.Ume.ui.adapter.explore

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.shierke.Ume.R
import kotlinx.android.synthetic.main.item_search_result_head.view.*
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.Glide
import com.shierke.Ume.ui.activity.explore.ExploreUserPrincipalActivity
import com.shierke.Ume.util.click


/**
 * Create by Ybx
 * on 2020-10-15
 * Desribe:
 */
class SearchResultHeadAdapter : RecyclerView.Adapter<SearchResultHeadAdapter.ViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {

        val view =
            LayoutInflater.from(parent.context)
                .inflate(R.layout.item_search_result_head, null, false)


        return ViewHolder(view)

    }

    override fun getItemCount() = 10

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.onBind()
    }


    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

        fun onBind() {
            with(itemView) {
                Glide.with(this)
                    .load(R.mipmap.search_result_head)
                    .apply(RequestOptions.bitmapTransform(CircleCrop()))
                    .into(headImage)

                rootView.click {
                    ExploreUserPrincipalActivity.startActivity(context)
                }
            }
        }
    }

}